<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function minimumCost(cost) {
      let a = 0
      cost.sort((a, b) => b - a)
      for (let i = 0, j = 1; i < cost.length; i++, j++)
        j % 3 !== 0 ? a += cost[i] : j = 0
      return a
    };
    console.log(minimumCost(cost = [1, 2, 3]))
  </script>
</body>

</html>